package category

import (
	"fmt"
	"gin_demo/utility"

	"github.com/gin-gonic/gin"
)

var Category = cCategory{}

type cCategory struct{}

//@Summary  后台分类数据列表接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param Limit query int true "一次性最大页数"
//@Param Page query int true "当前页数"
//@Router  /backend/category/list  [get]
//@version 1.0
func (c *cCategory) List(ctx *gin.Context) {
	req := PageListReq{}
	if err := ctx.ShouldBind(&req); err != nil {
		fmt.Printf("err: %v\n", err)
		utility.Fail(ctx, err.Error())
	} else {
		List(ctx, req)
	}
}

//@Summary  文件上传接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Accept multipart/form-data
//@Param file formData file true "file"
//@Router  /backend/upload_file  [post]
//@version 1.0
func (c *cCategory) Create(ctx *gin.Context) {
	req := AddCategoryReq{}
	if err := ctx.ShouldBindJSON(&req); err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		Create(ctx, req)
	}
}

//@Summary  后台分类数据删除接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param data body category.SoftDeleteReq{} true "删除请求参数"
//@Router  /backend/category/del  [delete]
//@version 1.0
func (c *cCategory) Delete(ctx *gin.Context) {
	req := SoftDeleteReq{}
	if err := ctx.ShouldBind(&req); err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		Delete(ctx, req)
	}
}

//@Summary  后台分类数据更新接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param data body category.UpdateCategoryReq{} true "更新请求参数"
//@Router  /backend/category/update  [put]
//@version 1.0
func (c *cCategory) Update(ctx *gin.Context) {
	req := UpdateCategoryReq{}
	if err := ctx.ShouldBind(&req); err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		Update(ctx, req)
	}
}
